const app = getApp();

// 交易市场
const tabs1 = [{
	url: '/pages/management/employee/employee',
	icon: '../../../assets/image/management/employee.png',
	name: '员工',
	role: 1
}, {
	url: '/pages/management/farmer/farmer',
	icon: '../../../assets/image/management/farmer.png',
	name: '农户',
	role: 1
}, {
	url: '/pages/management/owner/owner',
	icon: '../../../assets/image/management/owner.png',
	name: '货主',
	role: 1
}, {
	url: '/pages/management/pack/pack',
	icon: '../../../assets/image/management/pack.png',
	name: '包装',
	role: 1
}, {
	url: '/pages/management/bank-card/index',
	icon: '../../../assets/image/management/bank-card.png',
	name: '银行卡',
	role: 1
}, {
	url: '/pages/management/bill/bill',
	icon: '../../../assets/image/management/bill.png',
	name: '记账',
	role: 1
}, {
	url: '/pages/management/set/index',
	icon: '../../../assets/image/management/set.png',
	name: '业务',
	role: 1
}, {
	url: '/pages/management/operation/operation',
	icon: '../../../assets/image/management/operation.png',
	name: '操作',
	role: 1
},]

// 农户
const tabs2 = [{
	url: '/pages/management/bank-card/index',
	icon: '../../../assets/image/management/bank-card.png',
	name: '银行卡',
	role: 1
}, {
	url: '/pages/management/operation/operation',
	icon: '../../../assets/image/management/operation.png',
	name: '操作',
	role: 1
}, {
	url: '/pages/management/bill/bill',
	icon: '../../../assets/image/management/bill.png',
	name: '记账',
	role: 1
}, {
	url: '/pages/management/market/index',
	icon: '../../../assets/image/management/set.png',
	name: '交易',
	role: 1
},]

// 小工
const tabs3 = [{
	url: '/pages/management/bank-card/index',
	icon: '../../../assets/image/management/bank-card.png',
	name: '银行卡',
	role: 1
}, {
	url: '/pages/management/salary-management/index',
	icon: '../../../assets/image/management/employee.png',
	name: '工资',
	role: 1
}, {
	url: '/pages/management/operation/operation',
	icon: '../../../assets/image/management/operation.png',
	name: '操作',
	role: 1
}]

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		tabs: tabs1,
		roleName: '',
		userInfo: {
			userId: '',
			userName: '',
			mobile: '',
		}
	},
	onLoad: function (options) {
		this.init();
	},
	init() {
		// 获取用户信息
		let userInfo = app.globalData.userInfo;
		let roleName = userInfo.roleName;
		let role = userInfo.role;
		let tabs = tabs1;
		if (role == '1') {
			tabs = tabs1;
		}
		else if (role == '2') {
			tabs = tabs2;
		}
		else if (role == '3') {
			tabs = tabs3;
		}
		if (userInfo && userInfo.userDetail) {
			let userDetail = userInfo.userDetail;
			this.setData({
				tabs,
				roleName,
				userInfo: {
					userId: userDetail.id,
					userName: userDetail.realName,
					mobile: userDetail.mobile,
				}
			})
		}
	},
	// 个人中心
	toCenter() {
		wx.navigateTo({
			url: '/pages/management/center/center'
		})
	},
	// 消息通知
	toTip() {
		wx.navigateTo({
			url: '/pages/management/notify/index'
		})
	},
	toIdentity() {
		wx.navigateTo({
			url: '/pages/management/identity/identity'
		})
	},
	toPath(e) {
		let url = e.currentTarget.dataset['url'];
		wx.navigateTo({
			url
		})
	},
	onShow: function () {
		if (typeof this.getTabBar === 'function' && this.getTabBar()) {
			var selected = 4;
			if (app.globalData.userInfo.role == 2) {
				selected = 3;
			} else if (app.globalData.userInfo.role == 3) {
				selected = 2;
			}
			this.getTabBar().setData({
				selected: selected
			})
		}
	},
	toFeedback: function () {
		wx.navigateTo({
			url: '/pages/management/feedback/feedback',
		})
	},
	toAbout: function () {
		wx.navigateTo({
			url: '/pages/management/about/about',
		})
	}
})